﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Logging;

public partial class UserControl_UCDate : System.Web.UI.UserControl
{
    private ILog m_Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetControl();
        }
    }

    public DateTime? Date
    {
        get
        {
            try
            {
                DateTime date = new DateTime(int.Parse(ddlYear.SelectedValue), int.Parse(ddlMonth.SelectedValue), int.Parse(ddlDay.SelectedValue));
                return date;
            }
            catch (Exception ex)
            {
                m_Log.Error(ex);
                return null;
            }
        }
    }

    private void SetControl()
    {
        #region 生日年月日

        ddlYear.Items.Clear();
        ddlYear.Items.Add(new ListItem("西元年", ""));
        for (int i = DateTime.Today.Year; i > 1900; i--)
        {
            ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }

        ddlMonth.Items.Clear();
        ddlMonth.Items.Add(new ListItem("月", ""));
        for (int i = 1; i <= 12; i++)
        {
            ddlMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }

        ddlDay.Items.Clear();
        ddlDay.Items.Add(new ListItem("日", ""));
        for (int i = 1; i <= 31; i++)
        {
            ddlDay.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }

        #endregion
    }
}